package com.ui.design.main.base;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.ui.design.R;
import com.ui.design.main.constants.Constants;

@Route(path = Constants.Html)
public class HtmlActivity extends BaseActivity {

    @Autowired()
    String webUrl="";

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_html);
        WebView webView = findViewById(R.id.web);
        WebSettings settings = webView.getSettings();
        setTitleText(webUrl,"");
        settings.setJavaScriptEnabled(true);
        Log.e("TEST",webUrl);
        webView.loadUrl(webUrl);
    }

    @Override
    protected int initLayout() {
        return R.layout.activity_html;
    }

    @Override
    protected void initView() {
        WebView webView = findViewById(R.id.web);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        Log.e("TEST",webUrl);
        webView.loadUrl(webUrl);
        //系统默认会通过手机浏览器打开网页，为了能够直接通过WebView显示网页，则必须设置

        ProgressDialog dialog = ProgressDialog.show(HtmlActivity.this, "提示","正在载入博客地址", false,true);
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);// 设置进度条的形式为圆形转动的进度
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                dialog.dismiss();
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }
        });
    }

    @Override
    protected void initData() {
    }
}